package 力扣;

import org.hamcrest.Condition;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yyq
 * @create 2022-04-27 8:46
 */
public class leetcode17 {
    public static void main(String[] args) {
        leetcode17 leetcode17=new leetcode17();
        leetcode17.letterCombinations(new String("23"));
    }
    String[] letter = new String[]{"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    String s="";
    public List<String> letterCombinations(String digits) {
        List<String> list = new ArrayList<>();
        if(digits.equals("")) return list;
        int[] ints=new int[digits.length()];

        for (int i = 0; i < digits.length(); i++) {
            ints[i] = (int) digits.charAt(i) - (int)('0');
        }
        int startIndex = 0;
        backTracking(list,ints,startIndex);
        return list;
        
    }

    private void backTracking(List<String> list, int[] ints,int startIndex) {
        if(s.length() == ints.length){
            list.add(new String(s));
            return;
        }

        int index = ints[startIndex]-2;
        for (int j = 0; j < letter[index].length(); j++) {
            s = s + String.valueOf(letter[index].charAt(j));
            backTracking(list,ints,startIndex+1);
            s = s.substring(0,s.length()-1);
        }
    }
}

